package com.xmg.mgrsite.base;

import com.xmg.p2p.base.domain.SystemDictionary;
import com.xmg.p2p.base.domain.SystemDictionaryItem;
import com.xmg.p2p.base.query.PageResult;
import com.xmg.p2p.base.query.SystemDictionaryQueryObject;
import com.xmg.p2p.base.service.ISystemDictionaryItemService;
import com.xmg.p2p.base.service.ISystemDictionaryService;
import com.xmg.p2p.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * lcd  2020/5/14
 * Description:
 */
@Controller
public class SystemDictionaryController {
    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @RequestMapping("systemDictionary_list")
    public String SystemDictionaryIndex(Model model, @ModelAttribute("qo") SystemDictionaryQueryObject qo) {
        PageResult pageResult = systemDictionaryService.queryListSystemDictionary(qo);
        model.addAttribute("pageResult", pageResult);
        return "systemdic/systemDictionary_list";
    }

    @RequestMapping("systemDictionary_update")
    @ResponseBody
    public JSONResult systemDictionary_update(SystemDictionary dictionary) {
        systemDictionaryService.saveOrUpdate(dictionary);
        return new JSONResult();
    }

    @RequestMapping("systemDictionaryItem_list")
    public String SystemDictionaryItemIndex(Model model, @ModelAttribute("qo") SystemDictionaryQueryObject qo) {
        PageResult pageResult = systemDictionaryItemService.queryForPage(qo);
        model.addAttribute("pageResult", pageResult);
        model.addAttribute("systemDictionaryGroups", systemDictionaryService.findAll());
        return "systemdic/systemDictionaryItem_list";
    }

    @RequestMapping("systemDictionaryItem_update")
    @ResponseBody
    public JSONResult systemDictionaryItem_update(SystemDictionaryItem dictionaryItem) {
        systemDictionaryItemService.saveOrUpdate(dictionaryItem);
        return new JSONResult();
    }

}
